﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static NikeSale.Bll.DBSelect;
using NikeSale.Models;

namespace NikeSale.Ull
{
    public partial class AddTypeForm : Form
    {
        public AddTypeForm()
        {
            InitializeComponent();

            this.cb_ParentType.Items.Add(new Models.ComboxItem("无", "0"));
            this.cb_ParentType.Items.AddRange(GoodsClassIfication.GetParentTypes());
            this.cb_ParentType.SelectedIndex = 0;
        }

        private void bt_Add_Click(object sender, EventArgs e)
        {
            if (this.tb_TypeName.Text.Trim().Length==0)
            {
                this.tb_TypeName.Text = string.Empty;
                Methods.ShowPrompt($"类名不能为空", 1500);
                return;
            }
            if (GoodsClassIfication.HasTypeName(this.tb_TypeName.Text))
            {
                Methods.ShowPrompt($"已经包含了<{this.tb_TypeName.Text}>类,添加失败!",1500,20);
                return;
            }
            string id = ((ComboxItem)this.cb_ParentType.Items[this.cb_ParentType.SelectedIndex]).ID;
            GoodsClassIfication.InsertTypeInfo(this.tb_TypeName.Text, id);
            Methods.ShowPrompt("新增类插入成功!");
        }
    }
}
